<template>
  <div>
    <Spin :spinning="loading" tip="Loading...">
      <div style="padding-top: 1rem;"></div>
    <!-- table -->
    <FormPanel ref="formPanel" :list="formList" :cols="1" :formType="'add'" labelWidth="110" :isSubmitBtn="false" @formChange="formChangeHandle" />

    <div style="padding-top: 1rem;"></div>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <multiuse-button type="primary" :click="saveDialog.bind()">保 存</multiuse-button>
      <multiuse-button @click="closeDialog">关 闭</multiuse-button>
    </div>
    </Spin>
  </div>
</template>
<script>
import { editSave ,getTjdetail} from '@/api/claim/factory/FaultReasonMaintain';
export default {
  props: ['type', 'rowData'],
  components: {
  },
  data() {
    return {
      loading: false,
      visible: false,
      visibleDrawer: false,
      visibleAdd: false,
      flterValue: {}, //参数
      fetchParams: {}, //ipa 接口
      formList: this.createFormList(),
      saveData: null,
      val: null,
    };
  },
  created() {
  },
  mounted() {
    this.getDetailFun(this.rowData.frId);
  },
  methods: {
    async getDetailFun(id) {
      this.loading = true;
      let res = (await getTjdetail({ id: id })).data;
      for (let i in res) {
        this.formList.map(x => {
          if (x.fieldName == i) {
            x.initialValue = res[i];
          }
        });
      }

      this.ownerCode = res.ownerCode;
      this.appId = res.appId;
      this.ownerParCode = res.ownerParCode;
      this.createdBy = res.createdBy;
      console.log(res, 'res');
      this.loading = false;
    },
    formChangeHandle(val) {
      console.log(val);
      this.saveData = val;
    },
    async saveDialog() {
      this.$refs.formPanel.SUBMIT_FORM();
      if (this.saveData !== null) {
        console.log("faqq");
         console.log(this.saveData);
        this.saveData.ownerCode = this.ownerCode;
        this.saveData.ownerParCode = this.ownerParCode;
        this.saveData.appId = this.appId;
        this.saveData.frId=this.rowData.frId;
        this.saveData.isDeleted=this.rowData.isDeleted;
        this.saveData.createdBy=this.createdBy;
        this.saveData.createdAt=this.rowData.createdAt;
         this.saveData.isDeleted=this.rowData.isDeleted;
        this.loading = true;
        let res = await editSave(this.saveData);
        console.log(res);
        if (res.resultCode === 200) {
          this.$emit('save');
          return this.$notify.success({ title: '提示信息', message: '保存成功' });
        } else {
          this.loading = false;
        }
      }
    },
    //搜索获取数据
    changeHandle(val) {
      this.fetchParams = val;
      console.log(val);
    },
    //保存
    chooseOrderNo() {
      this.visibleDrawer = true;
    },
    closeAdd() {
      this.visibleDrawer = false;
      this.fetchParams = { ...this.fetchParams };
    },
    saveAdd() {
      this.visibleDrawer = false;
      this.fetchParams = { ...this.fetchParams };
    },
    //取消操作
    closeDialog() {
      this.$emit('close', { visible: false, data: this.selectedRows, type: 'close' });
    },
    createFormList() {
       return [
         {
           type: 'INPUT',
           label: '故障原因代码',
           fieldName: 'frCode',
           placeholder: '请输入故障原因代码...',
           initialValue: '',
           disabled: true,
           readonly: true,
           rules: [{required: true, message: '请输入故障原因代码...', trigger: 'change'}],
         },
         {
           type: 'INPUT',
           label: '故障原因描述',
           fieldName: 'frName',
           placeholder: '请输入故障原因描述...',
           initialValue: '',
           maxlength: 100,
           rules: [{required: true, message: '请输入原故障原因描述...', trigger: 'change'}],
         },
         {
           type: 'SELECT',
           label: '是否有效',
           placeholder: '请选择是否有效...',
           filterable: true,
           fieldName: 'frStatus',
           itemList: [{text: '否', value: 0}, {text: '是', value: 1}],
           rules: [{required: true, message: '请选择是否有效...', trigger: 'change'}]
         }
       ];
    }
  }
};
</script>

<style lang="less" scoped></style>
